<!--
 * @Description: 
 * @Version: V1.0.0
 * @Author: 周艳凯 484894717@qq.com
 * @Date: 2024-10-23 16:29:46
 * @LastEditors: 周艳凯 484894717@qq.com
 * @LastEditTime: 2024-10-23 21:15:13
 * @FilePath: slider-dots.vue
 * Copyright 2024 Marvin, All Rights Reserved. 
 * 2024-10-23 16:29:46
-->
<template>
  <view :class="classNames">
    <view
      v-for="(item, index) in data"
      :key="index"
      :style="getStyle(item.key)"
      class="arco-slider-dot-wrapper"
    >
      <view
        :class="[
          `arco-slider-dot`,
          { ['arco-slider-dot-active']: item.isActive },
        ]"
      >
      </view>
    </view>
  </view>
</template>

<script lang="ts">
import { computed, defineComponent } from "vue";
const SliderDots = defineComponent({
  name: "SliderDots",
  options: {
    // 虚拟化节点
    virtualHost: true,
  },
  props: {
    data: {
      type: Array,
      required: true,
    },
    min: {
      type: Number,
      required: true,
    },
    max: {
      type: Number,
      required: true,
    },
    direction: {
      type: String,
      default: "horizontal",
    },
  },
  setup(props) {
    const prefixCls = "arco-slider-dots";
    const getStyle = (value) =>
      getPositionStyle(
        getOffsetPercent(value, [props.min, props.max]),
        props.direction,
      );

    const getOffsetPercent = (value, [min, max]) => {
      const percent = Math.max((value - min) / (max - min), 0);
      return `${Math.round(percent * 10000) / 100}%`;
    };

    const getPositionStyle = (offset, direction) => {
      return direction === "vertical" ? { bottom: offset } : { left: offset };
    };

    const classNames = computed(() => {
      return [prefixCls];
    });

    return {
      prefixCls,
      classNames,
      getStyle,
    };
  },
});
export default SliderDots;
</script>
